package org.njo.webapp.root.action.dts.generator.maintenance;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ComparatorChain;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.njo.webapp.root.action.GenericAction;
import org.njo.webapp.root.model.activity.DTSActivity;
import org.njo.webapp.root.utility.ObjectNotExistsException;

public class LoadMaintenanceAction extends GenericAction {

    // --------------------------------------------------------- Public Methods

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping  The ActionMapping used to select this instance
     * @param form     The optional ActionForm bean for this request (if any)
     * @param request  The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @throws Exception if the application business logic throws
     *                   an exception
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        DTSActivity dtsactivity = new DTSActivity();

        String gen_name = request.getParameter("gen_name");
        // TODO check input

//        try {
//            Object ddlgen = dtsactivity.getDDLGEN(gen_name);
//            request.setAttribute("ddlgen", ddlgen);
//        } catch (ObjectNotExistsException e) {
//            // TODO out message
//        }
//        
//        List toKindList = dtsactivity.getDBKindList();
//        request.setAttribute("to_kind_list", toKindList);
//
//        // 取得字段集信息
//        List fieldSetList = dtsactivity.getFieldSetList();
//        // 对列表排序
//        List sortFieldSets = new ArrayList();
//        sortFieldSets.add(new BeanComparator("field_set_physical_name"));
//        Collections.sort(fieldSetList, new ComparatorChain(sortFieldSets));
//        
//        request.setAttribute("fieldSetList", fieldSetList);

        return (new ActionForward("/dts.gt.editmaintenance.tiles", false));
    }

}
